import { PixelRatio, Platform } from 'react-native';
import {
  SCREEN_HEIGHT,
  SCREEN_WIDTH,
  IS_TABLET_DEVICE,
  TABLET_WIDTH
} from '../constant';

export const textInputFontSize = (fontSize: number): number => {
  return Platform.OS === 'android'
    ? fontSize / PixelRatio.getFontScale()
    : fontSize;
};

export const PHONE_UI_WIDTH = 640;
export const PHONE_UI_HEIGHT = 360;

const phoneMinScale =
  Math.min(
    Math.max(SCREEN_HEIGHT, SCREEN_WIDTH),
    IS_TABLET_DEVICE ? TABLET_WIDTH : Math.min(SCREEN_HEIGHT, SCREEN_WIDTH)
  ) / PHONE_UI_HEIGHT;
const phoneMaxScale =
  Math.max(
    Math.max(SCREEN_HEIGHT, SCREEN_WIDTH),
    IS_TABLET_DEVICE ? TABLET_WIDTH : Math.min(SCREEN_HEIGHT, SCREEN_WIDTH)
  ) / PHONE_UI_WIDTH;
const phoneScale =
  phoneMinScale <= phoneMaxScale ? phoneMinScale : phoneMaxScale;

export const phonePx = (size: number): number => phoneScale * size;
export const px = (size: number): number => phonePx(size) / 2;

export const WEB_VIEW_SCALE = phoneScale;
